#!/usr/bin/python

import twitter
import cookielib, urllib2
# from auth import username, password

# username = raw_input('Username: ')
# password = raw_input('Password: ')

username = 'username'
password = 'password'
dstid = 'zellux'
dstlist = 'fudan'
srcid = 'luosheng'
srclist = 'fudan'

api = twitter.Api(username=username, password=password)
# api.SetProxy('10.131.251.101', '8808')

print 'Fetching list %s/%s' % (dstid, dstlist)
dstusers = api.GetListMembers(dstid, dstlist)
print 'Total: ' + str(len(dstusers)) + ' users'

dstset = set([u.screen_name for u in dstusers])

print '\nFetching list %s/%s' % (srcid, srclist)
srcusers = api.GetListMembers(srcid, srclist)
print 'Total: ' + str(len(srcusers)) + ' users'

srcset = set([u.screen_name for u in srcusers])

diffset = srcset - dstset
if len(diffset) == 0:
    print '\nNo modification'
    exit(0)
       
print '\nNew users:'
for u in diffset:
    print u
diffusers = filter(lambda u: u.screen_name in diffset, srcusers)

ans = raw_input('\nAdd these users in your list? (y/[n])')
if ans.strip() == 'y':
    for u in diffusers:
        print 'Adding %s[%s]...' % (u.screen_name, u.id)
        api.AddListMember(dstid, dstlist, u.id)

